package com.twu.biblioteca;

import com.twu.biblioteca.Book;
import com.twu.biblioteca.exception.NoSuchBookException;

import java.util.ArrayList;
import java.util.List;


public class BookManager {

    private List<Book> bookList = new ArrayList<Book>();

    public BookManager(){
        Book bookOne = new Book("pro git", 1);
        Book bookTwo = new Book("gone with the wind", 2);
        Book bookThree = new Book("happiness", 3);
        bookList.add(bookOne);
        bookList.add(bookTwo);
        bookList.add(bookThree);
    }

    public List<Book> getBooks() {
        return bookList;
    }

    public Book getBookById(int id) throws NoSuchBookException {
        for (Book book : bookList) {
            if (id == book.getId()) {
                return book;
            }
        }
        throw new NoSuchBookException(NoSuchBookException.LACK_BOOK_TIP);
    }

    public boolean isBookAvailable(int id) {
        for (Book book : bookList) {
            if (id == book.getId() && (!book.isReserved())) {
                return true;
            }
        }
        return false;
    }

}
